package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.Notice
import com.cheyun.netsalev3.utils.MySharedPreferences
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlin.reflect.KFunction1

class NewsSetRepository {
    fun setNotice(hashMap: HashMap<String, String>, kFunction1: KFunction1<@ParameterName(name = "item") Notice, Unit>) {
        ApiClient.getInstance().getNotice(hashMap)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<Notice>>() {
                    override fun onSuccess(t: BaseResp<Notice>) {
                        t.data?.apply {
                            MySharedPreferences.putNotice(this)
                            kFunction1(this)
                        }
                    }

                    override fun onError(ex: ApiException) {

                    }


                })

    }
}